import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/login'

Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        component: Login,
    },
    {
        path: '/login',
        name: 'Login',
        component: Login,
    },
    {
        path: '/index',
        name: 'Index',
        component: () => import('../views/index.vue'),
        meta: {
            isLogin: true,
            roles: ['boss', 'leader', 'staff']
        },
        children: [
            {
                path: '/index/',
                redirect: '/index/index',
                meta: {
                    isLogin: true,
                    roles: ['boss', 'leader', 'staff']
                },
            },
            {
                path: '/index/index',
                name: 'IndexPage',
                component: () => import('../components/indexCom/index.vue'),
                meta: {
                    isLogin: true,
                    roles: ['boss', 'leader', 'staff']
                },
            },
            {
                path: '/index/goods',
                name: 'Goods',
                component: () => import('../views/goodsPage.vue'),
                meta: {
                    isLogin: true,
                    roles: ['boss', 'leader', 'staff']
                }
            },
            {
                path: '/index/addGoods',
                name: 'addGood',
                component: () => import('../views/addGoods.vue'),
                meta: {
                    isLogin: true,
                    roles: ['boss', 'leader', 'staff']
                },

            },
            {
                path: '/index/goodsDetail',
                name: 'goodsDetail',
                component: () => import('../components/goodsCom/goodsDetail.vue'),
                meta: {
                    isLogin: true,
                    roles: ['boss', 'leader', 'staff']
                },
            },
            {
                path: '/index/staff',
                name: 'Staff',
                component: () => import('../views/staffPage.vue'),
                meta: {
                    isLogin: true,
                    roles: ['boss', 'leader', 'staff']
                },
            },
            {
                path: '/index/order',
                name: 'Order',
                component: () => import('../views/orderPage.vue'),
                meta: {
                    isLogin: true,
                    roles: ['boss', 'leader', 'staff']
                },
            },
            {
                path: '/index/oneOrderPage',
                name: 'Order2',
                component: () => import('../views/oneOrderPage.vue'),
                meta: {
                    isLogin: true,
                    roles: ['boss', 'leader', 'staff']
                },
            },
            {
                path: '/index/supplier',
                name: 'Supplier',
                component: () => import('../views/supplierPage.vue'),
                meta: {
                    isLogin: true,
                    roles: ['boss', 'leader', 'staff']
                },
            },
            {
                path: '/index/user',
                name: 'User',
                component: () => import('../views/userPage.vue'),
                meta: {
                    isLogin: true,
                    roles: ['boss', 'leader', 'staff']
                },
            }
        ]
    }
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})
/*router.beforeEach((to,from,next)=>{
    //to代表到哪里去，from代表从哪里来，next下一步，取消拦截
    if(to.meta.required){
        //需要验证 判断是否登录
        //console.log(store.state.user)
        if(store.state.user.data !== ''){
            next()
        }else {
            alert('登录失败，请重新输入')
            router.push('/login')
        }
    }else {
        //不需要验证
        next()
    }
})*/
export default router
